#include<bits/stdc++.h>
using namespace std;
int T;
int n[21];
int m[21];
int L[21];
int v[21];
int d[10001][21];
int v1[10001][21];
int a[10001][21];
int p1[10001][21];
void shuru(int X){
    for(int i=0;i<X;i++){
        cin>>n[i]>>m[i]>>L[i]>>v[i];
        for(int j=0;j<n[i];j++){
            cin>>d[j][i]>>v1[j][i]>>a[j][i];
            cin>>p1[j][i];
        }
    }
}
void cz(int y){
    for(int i=0;i<y;i++){
        int s1=0;
        int s2=m[i]-1;
        for(int j=m[i];j>1;j--){
            for(int i=0;i<j-1;i++){
                if(p1[i][y]>p1[i+1][y])   swap(p1[i][y],p1[i+1][y]);
            }
        }
        for(int i=0;i<n[i];i++){
            if(d[i][y]<=p1[m[i]-1][y]&&v1[i][y]>v[y])    s1++;
        }
        cout<<s1<<" "<<s2;
    }
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    shuru(T);
    cz(T);
}
